Skip to content

Comments

Working with lesson_3_branch.#4

Open
yaprogrammer18-yanchi wants to merge 18 commits intomainfrom
lesson_3_branch
Open

Working with lesson_3_branch.#4
yaprogrammer18-yanchi wants to merge 18 commits intomainfrom
lesson_3_branch

Conversation

@yaprogrammer18-yanchi
Copy link
Owner

Добавила файлы домашней работы от урока о Компиляции. Удалила папку самого урока чтобы не путаться. Теперь все файлы лежат только в src.

Copy link
Collaborator

@WoWaster WoWaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Общее замечание: вынесите всю логику в отдельные функции. Ну и посмотрите, какие комментарии правда нужны.


int main()
{
int* stackForBrackets = calloc(100, sizeof(int)); // сделаем большой стек состоящий из 100 нулей
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Писать комментарии --- отдельное искусство.
Но для начала есть два простых правила:

  1. Пишите комментарии над сущностью, которую комментируете.
  2. Если комментарий описывает ровно то, что написано в коде --- он не нужен.

scanf("%100[^\n]", stringWithBrackets); // ввели строку (огранчение 100 символов)

int count = 0; // счетчик того, сколько позиций занято в стеке
char str1 = ' '; // здесь будут символы из строки
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему эту переменную нельзя объявить внутри цикла?

Название переменной странное. Во-первых, она типа char, а называет как будто это строка. Во-вторых, слишком общее, поэтому Вам и захотелось написать комментарий.

Comment on lines 13 to 14
char str2 = '(';
char str3 = ')';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Научитесь объявлять константы. Хотя здесь они ни к чему. У Вас str2 и str3 встречаются ниже в коде по одному разу.


if (str1 == str2) // Ищем окрывающие скобки
{
stackForBrackets[count] = 2; // пусть 2 - это открывающая скобка
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А если вдруг кто-то напишет в стек значение 42, что будет? Используйте максимально узкие типы. Здесь гораздо лучше бы подошел bool.

count -= 1;
// этими действиями мы убрали закрытые скобки, будто их и не было
} else {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут какая-то лишняя строка

{
bool flag = true; // Это значит, что все символы строк совпадают, но если хотя бы один символ будет отличаться, будем менять на 0 и выходить из цикла
for (int j = 0; j < lenForSmallerString; j++) {
if (listForBiggerString[i + j] != listForSmallerString[j]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А если i = lenForBiggerString-1, а j = lenForSmallerString? Какие данные мы будем читать?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я так понимаю, что те, которые просто дальше лежат в памяти и уже никак не относятся к моей программе... Исправлю!

// пусть массив задан в программе
int listWithNumbers[] = { 0, 1, 3, 0, 6, 0, 7, 4, 6, 2, 0, 0 };
int countOfZeros = 0;
size_t lengthOfMassive = sizeof(listWithNumbers) / sizeof(int);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Massive --- это прилагательное! Array --- существительное.

size_t lenForBiggerString = sizeof(listForBiggerString) / sizeof(char);
size_t lenForSmallerString = sizeof(listForSmallerString) / sizeof(char) - 1; // так как последний символ нулевой

int countingOfEntry = 0; // счетчик вхождений
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entryCounter тогда уж. Counting обычно герундий

int main()
{
// пусть массив задан в программе
int listWithNumbers[] = { 0, 1, 3, 0, 6, 0, 7, 4, 6, 2, 0, 0 };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А список --- не массив.

{
// пусть массив задан в программе
int listWithNumbers[] = { 0, 1, 3, 0, 6, 0, 7, 4, 6, 2, 0, 0 };
int countOfZeros = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Либо numberOfZeroes, либо zeroCounter

{
//специальный счетчик, "(" это +1 ")" это -1. Если скобочная посл-ть правильная, counter == 0
int counter = 0;
bool bracketsExist = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта переменная правда нужна? Неужели счётчика не хватает?

int counter = 0;
bool bracketsExist = false;

for (int i = 0; i < 100; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему строго 100? Неужели если в строке будет 345 символов всю остальную логику нельзя будет использовать?

int main()
{
// пусть массив задан в программе
int ArrayWithNumbers[] = { 0, 1, 3, 0, 6, 0, 7, 4, 6, 2, 0, 0 };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почти :( тут с маленькой буквы

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эту задачу я зачту, а Вы поправите.


int entryCounter = 0;
// i - индекс эл-та с которого будем рассматривать большую строку
for (unsigned int i = 0; i < lenForBiggerString; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (unsigned int i = 0; i < lenForBiggerString; i++) {
for (unsigned i = 0; i < lenForBiggerString; i++) {

по стайлгайду

for (unsigned int i = 0; i < lenForBiggerString; i++) {
bool flag = true;
for (unsigned int j = 0; j < lenForSmallerString; j++) {
if (i + j < lenForBiggerString) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это можно сделать проще. Рассматривайте i не от 0 до lenForBiggerString - 1, а меньше, тогда будет меньше проблем с границами.

@yaprogrammer18-yanchi
Copy link
Owner Author

yaprogrammer18-yanchi commented Oct 12, 2025

Я изменила сообщение коммита и мне теперь выдает Merge branch 'lesson_3_branch' of github.com:yaprogrammer18-yanchi/C_Homework_ into lesson_3_branch... Можно я сделаю force push? :D

Copy link
Collaborator

@WoWaster WoWaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Осталось отформатировать... :(

@WoWaster
Copy link
Collaborator

И в своих ветках делайте force-push сколько хотите.

Copy link
Collaborator

@WoWaster WoWaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я не понял, почему у Вас раздублировались файлы

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачтено.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пусть уже будет.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants